<template>
	<div >


		<div align="left" style="float: left;margin-left: 60px;">
			<br />
			<el-button size="mini" @click="toAdd()">新增</el-button>
		</div>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column label="编号"  prop="oid" align="center">
			</el-table-column>
			<el-table-column label="问题"  prop="tid" align="center">
			</el-table-column>
			<el-table-column label="内容"  prop="content" align="center">
			</el-table-column>
			<!-- <el-table-column align="right">
				<template slot="header" slot-scope="scope">
					<el-input size="mini" placeholder="输入关键字搜索" />
				</template>
				<template slot-scope="scope">
					<el-button size="mini" @click="handleEdit(scope.$index,
	scope.row)">Edit</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">Delete
					</el-button>
				</template> -->
			<el-table-column label="操作" align="center">
				<template slot-scope="scope">
					<el-button size="mini" @click="handleEdit(scope.$index,
				scope.row)">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
					</el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script>
	export default {
		name: "Home",
		data() {
			return {
				tableData: []
			}
		},
		mounted() {
			this.queryByPage();
		},
		methods: {
			//查询页面
			queryByPage() {
				let _this = this;
				this.$axios.get('/option/2')
					.then(function(response) {
						_this.tableData = response.data;
					})
					.catch(function(error) {
						console.log(error);
					});
			},
			//删除一条记录
			handleDelete(index, row) {
				let _this = this;
				if (confirm("确定删除" + row.content + "吗?")) {
					this.$axios.delete('/option', {
							params: { // 使用params配置项传递参数
								oid: row.oid
							}
						})
						.then(function(response) {
							_this.queryByPage();
						})
						.catch(function(error) {
							console.log(error);
						});
				}
			},
			//新增跳转到编辑页面

			toAdd() {
				this.$router.push({
					name: 'AddOrEditBook'
				});
			},
			//修改跳转到编辑页面
			handleEdit(index, row) {
				this.$router.push({
					name: 'AddOrEditBook',
					params: {
						oid: row.oid,
						tid: row.tid,
						content: row.content
					}
				});
			}

		}


	}
</script>

<style>
</style>
